import { createAction } from 'redux-actions'
import { UPDATEPAGECOMPANYHOMEPAGE } from '../types/pagecompanyhomepage'
import { companyInfoRequest } from '../../../../service/org-operator-controller'
import { companyDetailFormat } from '../../../../service/format/companydetail'

export const DOREQUESTCOMPANYHOMEPAGE = createAction(UPDATEPAGECOMPANYHOMEPAGE, payload => {
  return new Promise(resolve => {
    companyInfoRequest(payload).then(({ data }) => {
      let CompanyFamousInfoDO = data.data || {}
      if (Object.keys(CompanyFamousInfoDO).length) {
        const formatdata = companyDetailFormat(CompanyFamousInfoDO || {})
        resolve({
          ...formatdata,
          showEmpty: false
        })
      } else {
        resolve({
          showEmpty: true
        })
      }
    })
  })
})
